#include <linux/types.h>
#include <linux/tty.h>

struct tty_struct g_tty;

void tty_int_handler(void)
{
    unsigned char ch;

    ch = getc();
    tty_insert_flip_char(&g_tty, ch, 0);
    tty_flip_buffer_push(&g_tty);
	// printf("this is %s(): %d\r\n", __func__, __LINE__);
}

unsigned char tty_read(void)
{
    n_tty_read(&g_tty);
}

static int tty_open(struct tty_struct *tty)
{
	memset(tty, 0, sizeof(struct tty_struct));
	tty->buf.head = tty->buf.tail = NULL;

    tty->read_buf = (char *)kmalloc(N_TTY_BUF_SIZE);
	memset(tty->read_buf, 0, N_TTY_BUF_SIZE);
	tty->read_head = tty->read_tail = tty->read_cnt = 0;

	tty->real_raw = 1;
	tty_buffer_init(tty);
}

void tty_init(void)
{
    tty_open(&g_tty);
}